package com.jarvis.dubbo;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.rpc.service.GenericService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * TODO XXX
 *
 * @author jarvis
 * created in 2020/9/17
 */
public class GenericConsumer {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("spring-context-consumer.xml");
        GenericService genericService = (GenericService) classPathXmlApplicationContext.getBean("genericService");
        System.out.println(genericService.$invoke("genericMethod", new String[]{"java.lang.String"}, new Object[]{"World"}));


        ApplicationConfig application = new ApplicationConfig();
        application.setName("yyy");

        // 连接注册中心配置
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("zookeeper://127.0.0.1:2181");
        ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<>();
        referenceConfig.setGeneric(true);
        referenceConfig.setApplication(application);
        referenceConfig.setRegistry(registry);
        referenceConfig.setInterface("com.jarvis.dubbo.service.IGenericService");
        GenericService configGenericService = referenceConfig.get();
        System.out.println(configGenericService.$invoke("genericMethod", new String[]{"java.lang.String"}, new Object[]{"World"}));
    }
}
